from django.contrib import admin
from content_adm.models import Course, Competence, Software, Profession, CompforProf, Mark, Student, MarkforComp, CompinCrs, Coefficient, Update

class CompetencesInline(admin.TabularInline):
	model = CompinCrs
	extra = 0

class SoftwareInline(admin.TabularInline):
	model = Software
	extra = 0

class CompforProfInline(admin.TabularInline):
	model = CompforProf
	extra = 0

class MarkInline(admin.TabularInline):
	model = Mark
	extra = 0

class MarkforCompInline(admin.TabularInline):
	model = MarkforComp
	extra = 0

class CompinCrsInline(admin.TabularInline):
	model = CompinCrs
	extra = 0

class UpdateAdmin(admin.ModelAdmin):
	ordering = ['upd_date']
	list_display = ('upd_type','upd_date')
	search_fields = ['upd_date']

class CourseAdmin(admin.ModelAdmin):
	inlines = [CompetencesInline]
	ordering = ['crs_name','crs_shortname']
	search_fields = ['crs_name']

class CompetenceAdmin(admin.ModelAdmin):
	inlines = [CompinCrsInline]
	ordering = ['cmpt_short_name']
	search_fields = ['cmpt_short_name']

class ProfessionAdmin(admin.ModelAdmin):
	inlines = [CompforProfInline]
	ordering = ['prof_name']
	search_fields = ['prof_name']

class StudentAdmin(admin.ModelAdmin):
	inlines = [MarkInline]
	list_display = ('lastname','firstname','mail','unique_number')
	ordering = ['lastname', 'firstname']
	search_fields = ['lastname']

class CompforProfAdmin(admin.ModelAdmin):
	list_display = ('prof','cmpt','importance')
	ordering = ['prof', 'cmpt']
	list_filter = ['prof', 'cmpt']

class MarkAdmin(admin.ModelAdmin):
	list_display = ('crs','stud','mark_final','mark_avg')
	ordering = ['crs', 'stud']
	list_filter = ['crs']
	search_fields = ['stud__lastname']

class MarkforCompAdmin(admin.ModelAdmin):
	list_display = ('cc','stud','mark_comp')
	ordering = ['cc', 'stud']
	list_filter = ['cc']
	search_fields = ['stud__lastname']

class SoftwareAdmin(admin.ModelAdmin):
	list_display = ('sftwr_name','cmpt')
	ordering = ['cmpt']
	list_filter = ['cmpt']
	search_fields = ['sftwr_name']

class CompinCrsAdmin(admin.ModelAdmin):
	list_display = ('cmpt', 'crs', 'percent', 'eff_factor')
	ordering = ['cmpt', 'crs', 'percent']
	list_filter = ['cmpt', 'crs']
	search_fields = ['cmpt__cmpt_short_name', 'crs__crs_name']

class CoefficientAdmin(admin.ModelAdmin):
	list_display = ('coef_name', 'coef_value', 'coef_description')
	ordering = ['coef_name']
	search_fields = ['coef_name']

admin.site.register(Course,CourseAdmin)
admin.site.register(Competence,CompetenceAdmin)
admin.site.register(Software,SoftwareAdmin)
admin.site.register(Profession,ProfessionAdmin)
admin.site.register(CompforProf,CompforProfAdmin)
admin.site.register(Mark,MarkAdmin)
admin.site.register(MarkforComp,MarkforCompAdmin)
admin.site.register(Student,StudentAdmin)
admin.site.register(CompinCrs,CompinCrsAdmin)
admin.site.register(Coefficient,CoefficientAdmin)
admin.site.register(Update,UpdateAdmin)
